package com.xcw.bos.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xcw.bos.dao.IFunctionDao;
import com.xcw.bos.domain.Function;
import com.xcw.bos.domain.User;
import com.xcw.bos.service.IFunctionService;
@Service
@Transactional
public class FunctionServiceImpl implements IFunctionService {
    @Resource
    private IFunctionDao functionDao;
	
	public List<Function> findAll() {
		
		return functionDao.findAll();
	}

	
	public void save(Function model) {
		Function parentFunction = model.getParentFunction();
		if(parentFunction != null){
			String id = parentFunction.getId();
			if(StringUtils.isBlank(id)){
				model.setParentFunction(null);
			}
		}
        functionDao.save(model);
	}

	//根据登录人查询对应的菜单数据
	public List<Function> findMenu(User loginUser) {
		List<Function> list = null;
		if(loginUser.getUsername().equals("admin")){
			//查询所有菜单数据
			list = functionDao.findAllMenu();
		}else{
			//普通用户，根据用户的角色查询对应的权限
			list = functionDao.findMenu(loginUser.getId());
		}
		return list;
	}

}
